use multi_support_app::{EchoReply, EchoRequest, test_server::Test};


use crate::{
    facade::{builder::Builder, test::TestFacade},
    provider::test::TestProvider,
};

#[derive(Debug)]
pub struct TestService;

#[tonic::async_trait]
impl Test for TestService {
    async fn echo(
        &self,
        request: tonic::Request<EchoRequest>,
    ) -> Result<tonic::Response<EchoReply>, tonic::Status> {
        let msg = &request.get_ref().message;
        let ret = TestProvider::builder().echo(msg.to_string());

        match ret {
            Ok(_v) => Ok(tonic::Response::new(EchoReply {
                message: format!("Echoing back: {}", _v),
            })),
            Err(_e) => Ok(tonic::Response::new(EchoReply {
                message: format!("Echoing error: {}", request.get_ref().message),
            })),
        }
    }
}
